home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Net / Utilities / Seer family 2.0 / seer_common / sc_pk_draw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-11-15  |  5.1 KB  |  184 lines  |  [TEXT/KAHL]

  1. /*
  2.     sc_draw_packets.c - draw the packet window
  3. */
  4. #include "sc.h"
  5. #include "sc_packet_window.h"
  6. #include "sc_seer_globals.h"
  7. #include "pdl_data.h"
  8. #include "OUT.h"
  9.  
  10. #define MAX_PAKS_PER_WINDOW 40    /*maximum number of displayed packets*/
  11.  
  12. /*
  13.    pak_height record of how many pixels high each packet is.
  14.    indexed by draw_packet_num (including the trailing white space).
  15.  
  16.     <0 if height is unknown
  17. */
  18. static int pak_height[MAX_PAKS_PER_WINDOW+1];
  19. static int numb_paks;            /*current number of displayed packets*/
  20.  
  21. /* packets have been flushed from the queue, update the packet display*/
  22. void new_pak_display()
  23. {GrafPtr save_port;
  24.  if(gl.wdf_packet==0)
  25.   return;
  26.  GetPort(&save_port);            /*save the old graf port*/
  27.  SetPort(gl.wdf_packet);           /*switch to the port to update*/
  28.  PAK_wdf->draw_packet_num=0;
  29.  PAK_wdf->draw_pak_max= -1;
  30.  inval_pak_cache();
  31.  InvalRect(&gl.wdf_packet->windat.port.portRect);
  32.  /* SetCtlValue crashes the system if control is not active */
  33.  if(FrontWindow() == &gl.wdf_packet->windat.port)
  34.   SetCtlValue(PAK_wdf->ctls[vscroll_ctl],0);
  35.  SetPort(save_port);
  36. }
  37.  
  38. /*inval_pak_cache - the window was scrolled backwards or something
  39.   like that so don't depend on the previously displayed text being valid
  40. */
  41. void inval_pak_cache()
  42. {numb_paks=0;
  43. }
  44.  
  45. /*print a line that text_pak made up*/
  46. void draw_flush(char*,int);
  47. void draw_flush(str,siz)
  48. register char *str;
  49. int siz;
  50. {if(siz!=0)
  51.      DrawText(str,0,siz);
  52.  MoveTo(gl.cur_windef->char_left_inset,
  53.            CUR_WINDOW->pnLoc.v+gl.cur_windef->char_height);
  54. }
  55. /*
  56.     draw_1_pak - draw the selected packet.  return true if it doesn't
  57.         exist
  58. */
  59. int draw_1_pak(int);
  60. static int draw_1_pak(sel_pak)
  61. int sel_pak;
  62. {int this_pak_size;
  63.  long the_packet_num;
  64.  
  65.  /*might this packet be valid already?*/
  66.  if(sel_pak<numb_paks)        /*yes, it was printed before*/
  67.    if((this_pak_size=pak_height[sel_pak])>=0) {/*is it valid on the screen now?*/
  68.      /*yes, wonderful the screen is already ok*/
  69.      /*move the pen to where it would have gone if we had needed to*/
  70.      /*draw this packet*/
  71.      MoveTo(gl.cur_windef->char_left_inset,this_pak_size);
  72.         return false;            /*the packet existed*/
  73.      }
  74.  
  75.  /* don't select packets out of range */
  76.  the_packet_num=PAK_wdf->draw_packet_num+sel_pak;
  77.  if(the_packet_num>PAK_wdf->draw_pak_max)
  78.      return true;
  79.  if(text_pak(sp_status->pre_pak_num+1+the_packet_num))
  80.      return true;        /* no such packet */
  81.  MoveTo(gl.cur_windef->char_left_inset,CUR_WINDOW->pnLoc.v+
  82.           (gl.cur_windef->char_height/2));
  83.  
  84.  numb_paks=max(numb_paks,sel_pak+1); /*say how many valid paks on screen*/
  85.  pak_height[sel_pak]=CUR_WINDOW->pnLoc.v;
  86.  
  87.  return false;                /*say we had a packet, don't quit yet*/
  88. }
  89.  
  90. /*
  91.     display packets begining with draw_packet_num onto gl.cur_windef->windat
  92.     for as many as will fit
  93. */
  94. void draw_packets(void);
  95. void draw_packets()
  96. {int scn_pak;
  97.  char data_buffer[OUT_BUF_SIZE];
  98.  out_start=data_buffer;         /* buffer lines here*/
  99.  out_stop=out_start+PAK_wdf->draw_pak_width;
  100.  out_flush=draw_flush;
  101.  
  102.  /*start drawing here*/
  103.  MoveTo(PAK_wdf->draw_pak_rect.left+gl.cur_windef->char_left_inset,
  104.      PAK_wdf->draw_pak_rect.top+
  105.          gl.cur_windef->char_height-
  106.          gl.cur_windef->char_descent);
  107.  
  108.  for(scn_pak=0;             /*display packets after draw_packet*/
  109.       scn_pak<MAX_PAKS_PER_WINDOW;
  110.       scn_pak++) {
  111.    if(draw_1_pak(scn_pak)) {        /*draw the current packet*/
  112.       Move(gl.cur_windef->char_left_inset,0);
  113.      DrawString("\p*** end of packet buffer ***");
  114.      break;}
  115.  
  116.    /*see if anything after the current y display location might be visible*/
  117.    /*off the end of the window?*/
  118.    if(CUR_WINDOW->pnLoc.v >= PAK_wdf->draw_pak_rect.bottom) {
  119.      numb_paks=max(0,numb_paks-1); /* last packet not compleatly drawn */ 
  120.      break;        /*yes, nothing else will be visible, so don't draw it*/
  121.      } /* end if ran off the end */
  122.    } /* end for scn_pak */
  123. }
  124.  
  125. /*process an update event*/
  126. void e_pak_update_event()
  127. {show_grow();
  128.  RectRgn(CUR_WINDOW->clipRgn,&PAK_wdf->draw_pak_rect);
  129.  numb_paks=0;
  130.  draw_packets();        /*draw needed parts of the packet window*/
  131.  RectRgn(CUR_WINDOW->clipRgn,&CUR_WINDOW->portRect);
  132. }
  133.  
  134. /*
  135.     see if there is valid information on the screen that can be scrolled
  136.     into place and save on redrawing, invalidate areas needing to
  137.     be redrawn
  138. */
  139. void scroll_n_inval(long);
  140. void scroll_n_inval(pak_dist)
  141. long pak_dist;
  142. {register int vdist;
  143.  register int i;
  144.  RgnHandle bad_rgn;
  145.  if(pak_dist==0) /* no jump, cache is fine */
  146.      return;
  147.  if((pak_dist<0)|| /* jump backwards, forget it */
  148.     (pak_dist>=numb_paks)) {
  149.      numb_paks=0;
  150.      InvalRect(&PAK_wdf->draw_pak_rect);
  151.     return;
  152.     }
  153.  
  154.  vdist=    (pak_height[pak_dist-1]+
  155.          gl.cur_windef->char_descent-gl.cur_windef->char_height);
  156.  
  157.  bad_rgn=NewRgn();
  158.  ScrollRect(&PAK_wdf->draw_pak_rect,
  159.      0,
  160.      - vdist,
  161.      bad_rgn);
  162.  InvalRgn(bad_rgn);
  163.  DisposeRgn(bad_rgn);
  164.  
  165.  numb_paks -= pak_dist;
  166.  for(i=0;i<numb_paks;i++)
  167.      pak_height[i] = pak_height[i+pak_dist] - vdist;
  168.  return;
  169. }
  170.  
  171. /*
  172.     see if there is valid information on the screen that can be scrolled
  173.     into place and save on redrawing
  174. */
  175. void scroll_draw_packets(pak_dist)
  176. long pak_dist;
  177. {scroll_n_inval(pak_dist);        /*invalidate any areas needing updating */
  178.  BeginUpdate(CUR_WINDOW);
  179.  EraseRect(&CUR_WINDOW->portRect); /*yes, clear the update area*/
  180.  draw_packets();
  181.  EndUpdate(CUR_WINDOW);
  182. }
  183.  
  184.